from django.db import models

class DataDictionary(models.Model):
    """
    字典
    """
    DataDictionaryId = models.CharField(max_length=36, null=True, blank=True, verbose_name='字典id')
    CompanyId = models.CharField(max_length=50, null=True, blank=True, verbose_name='企业id')
    ParentId = models.CharField(max_length=36, null=True, blank=True, verbose_name='父类字典')
    CategoryType = models.CharField(max_length=50, null=True, blank=True, verbose_name='字典类别')
    DictionaryCode = models.CharField(max_length=50, null=True, blank=True, verbose_name='字典类别')
    FullName = models.CharField(max_length=50, null=True, blank=True, verbose_name='字典名称')
    Remark = models.CharField(max_length=200, null=True, blank=True, verbose_name='备注')
    IsTree = models.BooleanField(null=True, blank=True, verbose_name="是否是树结构")
    IsEnabled = models.BooleanField(null=True, blank=True, verbose_name="是否可用")
    SortNo = models.IntegerField(null=True, blank=True, verbose_name="排序")
    pid = models.ForeignKey("self", null=True, blank=True, on_delete=models.SET_NULL, verbose_name="父类字典")
    CreateByUid = models.IntegerField(null=True, blank=True, verbose_name="创建人ID")
    AddByName = models.CharField(max_length=30, null=True, blank=True, verbose_name="创建人名称")
    UpdateByUid = models.IntegerField(null=True, blank=True,  verbose_name="更新人ID")
    UpdateByName = models.CharField(max_length=30, null=True, blank=True, verbose_name="更新人名称")
    AddDate = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    UpdateDate = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    def __str__(self):
        return self.FullName

    class Meta:
        managed = False  # False是不会为当前模型创建和删除数据表
        verbose_name = '字典'
        verbose_name_plural = verbose_name
        indexes = [
            models.Index(fields=['DataDictionaryId']),
            models.Index(fields=['DictionaryCode']),
        ]


class DataDictionaryDetail(models.Model):
    """
    字典详情
    """
    DataDictionaryDetailId = models.CharField(max_length=36, null=True, blank=True, verbose_name='字典详情id')
    DataDictionaryId = models.CharField(max_length=50, null=True, blank=True, verbose_name='字典id')
    ParentId = models.CharField(max_length=50, null=True, blank=True, verbose_name='父类字典')
    ParentCode = models.CharField(max_length=50, null=True, blank=True, verbose_name='字典id')
    DictionaryCode = models.CharField(max_length=50, null=True, blank=True, verbose_name='键')
    DictionaryValue = models.CharField(max_length=100, null=True, blank=True, verbose_name='值')
    FullName = models.CharField(max_length=300, null=True, blank=True, verbose_name='字典名称')
    Remark = models.CharField(max_length=200, null=True, blank=True, verbose_name='备注')
    IsTree = models.BooleanField(null=True, blank=True, verbose_name="是否是树结构")
    IsEnabled = models.BooleanField(null=True, blank=True, verbose_name="是否可用")
    SortNo = models.IntegerField(null=True, blank=True, verbose_name="排序")
    SortNoTwo = models.IntegerField(null=True, blank=True, verbose_name="查策网排序")
    CreateByUid = models.IntegerField(null=True, blank=True, verbose_name="创建人ID")
    AddByName = models.CharField(max_length=30, null=True, blank=True, verbose_name="创建人名称")
    UpdateByUid = models.IntegerField(null=True, blank=True, verbose_name="更新人ID")
    UpdateByName = models.CharField(max_length=30, null=True, blank=True, verbose_name="更新人名称")
    AddDate = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    UpdateDate = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    def __str__(self):
        return self.FullName

    class Meta:
        managed = False  # False是不会为当前模型创建和删除数据表
        verbose_name = '字典详情'
        verbose_name_plural = verbose_name
        indexes = [
            models.Index(fields=['DataDictionaryDetailId']),
            models.Index(fields=['DataDictionaryId']),
            models.Index(fields=['DictionaryCode']),
            models.Index(fields=['DictionaryValue']),
            models.Index(fields=['ParentCode']),
            models.Index(fields=['IsEnabled']),
            models.Index(fields=['ParentCode', 'IsEnabled']),
        ]
